<template>
  <view class="container">
    <view class="title">显示图片</view>
    <image 
      class="avatar" 
      :src="imageUrl" 
      mode="aspectFill"
    ></image>
    <button @click="chooseImage">选择图片显示</button>
    <button @click="previewImage">预览图片</button>
    <button @click="getImageInfo">获取图片信息</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imageUrl: '/static/logo.png'
    };
  },
  methods: {
    chooseImage() {
      uni.chooseImage({
        count: 1, 
        sourceType: ['album', ], 
        success: (res) => {
          this.imageUrl = res.tempFilePaths[0];
        }
      });
    },
    previewImage() {
      if (!this.imageUrl) {
        uni.showToast({ title: '请先选择图片', icon: 'none' });
        return;
      }
      uni.previewImage({
        urls: [this.imageUrl], 
        current: this.imageUrl 
      });
    },
    getImageInfo() {
      if (!this.imageUrl) {
        uni.showToast({ title: '请先选择图片', icon: 'none' });
        return;
      }
      uni.getImageInfo({
        src: this.imageUrl,
        success: (info) => {
          uni.showModal({
            title: '图片信息',
            content: `宽：${info.width}px\n高：${info.height}px\n类型：${info.type}`,
            showCancel: false
          });
        }
      });
    }
  }
};
</script>

<style scoped>
.container {
  padding: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.title {
  font-size: 32rpx;
  margin-bottom: 30rpx;
}
.avatar {
  width: 200rpx;
  height: 200rpx;
  border-radius: 50%;
  margin-bottom: 30rpx;
}
button {
  width: 600rpx;
  margin-bottom: 20rpx;
}
</style>